package com.drcoffee.drcoffeemall.service.impl;

import com.drcoffee.drcoffeemall.entry.CssOrientation;
import com.drcoffee.drcoffeemall.entry.Explosion;
import com.drcoffee.drcoffeemall.mapper.ExplosionMapper;
import com.drcoffee.drcoffeemall.service.ExplosionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public class ExplosionServiceImpl implements ExplosionService {

    @Autowired
    ExplosionMapper explosionMapper;

    /*
     * 根据ID查询爆炸图
     * */
    @Override
    public Map<String, Object> getExplosionById(Integer id) {
        Map<String, Object> resultMap = new HashMap<>();
        try {
            Explosion explosion = explosionMapper.getExplosionById(id);
            resultMap.put("message", "查询成功");
            resultMap.put("explosion", explosion);
        } catch (Exception e) {
            resultMap.put("message", "查询失败");
            resultMap.put("reason", e.getMessage());
            log.error("===================== uploadImage()异常： =====================", e);
        }
        return resultMap;
    }

    /*
     * 根据机器ID查询关联爆炸图
     * */
    @Override
    public ResponseEntity<Object> getExplosionByMachineId(Integer machine_id) {
        return new ResponseEntity<>(explosionMapper.getExplosionByMachineId(machine_id), HttpStatus.OK);
    }


    /*
     * 查询包插图关联的定位点
     * */
    @Override
    public Map<String, Object> getCssOrientation(Integer id) {
        Map<String, Object> resultMap = new HashMap<>();
        List<CssOrientation> cssOrientation = explosionMapper.getCssOrientation(id);
        resultMap.put("result", 1);
        resultMap.put("cssOrientationList", cssOrientation);
        return resultMap;
    }
}
